<?=$this->header(true)?>


    <?=$this->menu("staff")?>


    <h1><?=$this->message("nav.staff")?></h1>


    <? /* Breadcrums route */ ?>
    <?=$this->route(
        array(
            array(
                "name"=>$this->message("nav.staff"),
                "href"=>"staff/list"
            ),
            array(
                "name"=>($this->staffForm->getStaff()->getStaffId() > 0 ?
                    $this->message("route.edit", _Core::BUNDLE) . " " .
                        "\"".$this->staffForm->getStaff()->getUserName()."\" " :
                    $this->message("route.new", _Core::BUNDLE) . " " .$this->message("label.item", _Staff::BUNDLE))
            )
        )
    )?>


    <? /* Show error messages */ ?>
    <?=$this->errors(null, _Staff::BUNDLE)?>


    <form id="<?=get_class($this->staffForm)?>" action="staff/save" method="post" enctype="multipart/form-data">

        <div>
            <input type="hidden"
                   name="staff->staffId"
                   value="<?=$this->staffForm->getStaff()->getStaffId()?>" />
        </div>

        <fieldset>

            <legend><?=$this->message("label.required")?></legend>

            <table cellspacing="0" cellpadding="0" class="form">
            <tr class="ctrl<?=$this->error("staff->firstname")?>">
                <th><label for="staff_firstname"><?=$this->message("prompt.firstname", _Staff::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <input name="staff->firstname"
                           id="staff_firstname"
                           value="<?=$this->staffForm->getStaff()->getFirstname()?>"
                           maxlength="32"
                           type="text"
                           class="textInput" />
                </td>
            </tr>
            <tr class="ctrl<?=$this->error("staff->surname")?>">
                <th><label for="surname"><?=$this->message("prompt.surname", _Staff::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <input name="staff->surname"
                           id="surname"
                           value="<?=$this->staffForm->getStaff()->getSurname()?>"
                           maxlength="32"
                           type="text"
                           class="textInput" />
                </td>
            </tr>
            <tr class="ctrl<?=$this->error("staff->username")?>">
                <th><label for="username"><?=$this->message("prompt.username", _Staff::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <input name="staff->username"
                           id="username"
                           value="<?=$this->staffForm->getStaff()->getUserName()?>"
                           maxlength="32"
                           type="text"
                           class="textInput" />
                           <p class="hint"><?=$this->message("note.username", _Staff::BUNDLE)?></p>
                </td>
            </tr>

            <? /* Passwords are required when editing new Staff. See below for optional passwords */ ?>
            <? if($this->staffForm->getStaff()->getStaffId() <= 0): ?>

                <tr class="ctrl<?=$this->error("staff->password")?>">
                    <th><label for="password"><?=$this->message("prompt.password", _Staff::BUNDLE)?></label></th>
                    <th class="required"><em>*</em></th>
                    <td>
                        <input name="staff->password"
                               id="password"
                               value="<?=$this->staffForm->getStaff()->getPassword()?>"
                               maxlength="32"
                               type="password"
                               class="textInput" />
                        <p class="hint"><?=$this->message("note.password", _Staff::BUNDLE)?></p>
                    </td>
                </tr>
                <tr class="ctrl<?=$this->error("password2")?>">
                    <th><label for="password2"><?=$this->message("prompt.password2", _Staff::BUNDLE)?></label></th>
                    <th class="required"><em>*</em></th>
                    <td>
                        <input name="password2"
                               id="password2"
                               value="<?=$this->staffForm->getPassword2()?>"
                               maxlength="32"
                               type="password"
                               class="textInput" />
                    </td>
                </tr>

            <? endif; ?>

            <tr class="ctrl<?=$this->error("roles")?>">
                <th><label for="roles"><?=$this->message("prompt.roles", _Staff::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <select name="roles[]" id="roles" multiple="multiple" size="5" class="textInput">
                        <? foreach($this->roles() as $role): ?>
                            <option
                                value="<?=$role->getRolename()?>"
                                <?=in_array($role->getRolename(), $this->staffForm->getRoles()) ? " selected=\"selected\"" : ""?>>
                                <?=$role->getDescription()?>
                            </option>
                        <? endforeach; ?>
                    </select>
                    <p class="hint"><?=$this->message("note.multiple", _Core::BUNDLE, null, null, false)?></p>

                </td>
            </tr>

            <tr class="ctrl<?=$this->error("staff->languageCode")?>">
                <th><label for="staff_languageCode"><?=$this->message("prompt.language", _Staff::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <select name="staff->languageCode" id="staff_languageCode" class="icon-menu">
                        <option value="">--</option>
                        <? foreach($this->languages(false, true) as $language): ?>
                            <option
                                value="<?=$language->getCode()?>"
                                style="background-image:url(static.php?file=<?=$this->image("cms/core/view/gfx/flag/".$language->getCode().".png")?>);"
                                <?=$language->getCode() == $this->staffForm->getStaff()->getLanguageCode() ? " selected=\"selected\"" : ""?>>
                                    <?=$language->getName()?>
                            </option>
                        <? endforeach; ?>
                    </select>
                </td>
            </tr>

            </table>

        </fieldset>


        <fieldset>

            <legend><?=$this->message("label.optional")?></legend>

            <table cellspacing="0" cellpadding="0" class="form">
            <tr class="ctrl<?=$this->error("formImage")?>">
                <th><label for="formImage"><?=$this->message("label.image", _Core::BUNDLE)?></label></th>
                <th class="required"><em>&nbsp;</em></th>
                <td>
                    <? if(!is_null($this->staffForm->getStaff()) &&
                        $this->staffForm->getStaff()->getImageId() > 0 &&
                        !is_null($this->staffForm->getStaff()->getImageRelatedByImageId())) { ?>

                        <input type="hidden"
                               name="staff->imageRelatedByImageId->imageId"
                               value="<?=$this->staffForm->getStaff()->getImageId()?>" />
                        <input type="hidden"
                               name="staff->imageRelatedByThumbnailId->imageId"
                               value="<?=$this->staffForm->getStaff()->getThumbnailId()?>" />

                        <input type="hidden"
                               name="staff->imageRelatedByImageId->binaryFileId"
                               value="<?=$this->staffForm->getStaff()->getImageRelatedByImageId()->getBinaryFileId()?>" />
                        <input type="hidden"
                               name="staff->imageRelatedByThumbnailId->binaryFileId"
                               value="<?=$this->staffForm->getStaff()->getImageRelatedByThumbnailId()->getBinaryFileId()?>" />

                        <img src="image?id=<?=$this->staffForm->getStaff()->getImageId()?>"
                             width="<?=$this->staffForm->getStaff()->getImageRelatedByImageId()->getWidth()?>"
                             height="<?=$this->staffForm->getStaff()->getImageRelatedByImageId()->getHeight()?>" alt="" />

                        <input type="checkbox" name="deleteImage" value="true" id="deleteImage" /> <label for="deleteImage"><?=$this->message("label.image.delete", _Core::BUNDLE)?></label>

                        <br /><br />

                    <? } ?>

                    <input type="file" name="formImage" />

                    <p class="hint"><?=$this->message("note.image.resize", _Core::BUNDLE)?> <?=$this->imageProps($this->param(_Core::SETTING_LIST))->getImageWidth()?>x<?=$this->imageProps($this->param(_CORE::SETTING_LIST))->getImageHeight()?>.</p>

                </td>
            </tr>
            <tr class="ctrl<?=$this->error("staff->region")?>">
                <th><label for="surname"><?=$this->message("prompt.region", _Staff::BUNDLE)?></label></th>
                <th class="required"><em>&nbsp;</em></th>
                <td>
                    <input name="staff->region"
                           id="surname"
                           value="<?=$this->staffForm->getStaff()->getRegion()?>"
                           maxlength="32"
                           type="text"
                           class="textInput" />
                </td>
            </tr>
            <tr class="ctrl<?=$this->error("staff->sector")?>">
                <th><label for="surname"><?=$this->message("prompt.sector", _Staff::BUNDLE)?></label></th>
                <th class="required"><em>&nbsp;</em></th>
                <td>
                    <input name="staff->sector"
                           id="surname"
                           value="<?=$this->staffForm->getStaff()->getSector()?>"
                           maxlength="32"
                           type="text"
                           class="textInput" />
                </td>
            </tr>
            <tr class="ctrl<?=$this->error("staff->organization")?>">
                <th><label for="surname"><?=$this->message("prompt.organization", _Staff::BUNDLE)?></label></th>
                <th class="required"><em>&nbsp;</em></th>
                <td>
                    <input name="staff->organization"
                           id="surname"
                           value="<?=$this->staffForm->getStaff()->getOrganization()?>"
                           maxlength="32"
                           type="text"
                           class="textInput" />
                </td>
            </tr>
            <tr class="ctrl<?=$this->error("staff->newsletter")?>">
                <th><label for="staff_newsletter"><?=$this->message("prompt.newsletter", _Staff::BUNDLE)?></label></th>
                <th class="required"><em>&nbsp;</em></th>
                <td>
                    <input name="staff->newsletter"
                           id="staff_newsletter"
                           value="1"
                           type="checkbox"
                           <?=$this->staffForm->getStaff()->getNewsletter() ? " checked=\"checked\"" : ""?> />
                </td>
            </tr>

            <? /* Passwords are optional when editing existing Staff */ ?>
            <? if($this->staffForm->getStaff()->getStaffId() > 0): ?>

                <tr class="ctrl<?=$this->error("staff->password")?>">
                    <th><label for="password"><?=$this->message("prompt.password", _Staff::BUNDLE)?></label></th>
                    <th class="required"><em>&nbsp;</em></th>
                    <td>
                        <input name="staff->password"
                               id="password"
                               value="<?=$this->staffForm->getStaff()->getPassword()?>"
                               maxlength="32"
                               type="password"
                               class="textInput" />
                        <p class="hint"><?=$this->message("note.password", _Staff::BUNDLE)?></p>
                    </td>
                </tr>
                <tr class="ctrl<?=$this->error("password2")?>">
                    <th><label for="password2"><?=$this->message("prompt.password2", _Staff::BUNDLE)?></label></th>
                    <th class="required"><em>&nbsp;</em></th>
                    <td>
                        <input name="password2"
                               id="password2"
                               value="<?=$this->staffForm->getPassword2()?>"
                               maxlength="32"
                               type="password"
                               class="textInput" />
                    </td>
                </tr>

            <? endif; ?>
            </table>

        </fieldset>


        <div class="buttons">

            <input type="button"
                   onclick="to('staff/list')"
                   value="<?=$this->message("button.cancel", _Core::BUNDLE)?>"
                   class="button" />
            <input type="submit"
                   value="<?=$this->message("button.submit", _Core::BUNDLE)?>"
                   class="button" />

        </div>

    </form>

<?=$this->footer()?>